package com.k8s.base.domain;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Objects;

/**
 * A DictOwner.
 */
@Entity
@Table(name = "sys_dict_owner")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class DictOwner implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotNull
    @Column(name = "owner_type", nullable = false)
    private String ownerType;

    @NotNull
    @Column(name = "owner_id", nullable = false)
    private Long ownerId;

    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="dict_id", nullable = false)
    private Dict dict;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getOwnerType() {
        return ownerType;
    }

    public DictOwner ownerType(String ownerType) {
        this.ownerType = ownerType;
        return this;
    }

    public void setOwnerType(String ownerType) {
        this.ownerType = ownerType;
    }

    public Long getOwnerId() {
        return ownerId;
    }

    public DictOwner ownerId(Long ownerId) {
        this.ownerId = ownerId;
        return this;
    }

    public void setOwnerId(Long ownerId) {
        this.ownerId = ownerId;
    }

    public Dict getDict() {
        return dict;
    }

    public DictOwner dict(Dict dict) {
        this.dict = dict;
        return this;
    }

    public void setDict(Dict dict) {
        this.dict = dict;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        DictOwner dictOwner = (DictOwner) o;
        if (dictOwner.id == null || id == null) {
            return false;
        }
        return Objects.equals(id, dictOwner.id);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id);
    }

    @Override
    public String toString() {
        return "DictOwner{" +
            "id=" + id +
            ", ownerType='" + ownerType + "'" +
            ", ownerId='" + ownerId + "'" +
            '}';
    }
}
